<?php

use yii\db\Migration;

class m171031_014745_create_manage_time extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%class_manage_time}}',[
                'class_id' => $this->integer()->defaultValue(0)->comment('班级id'),
                'class_day' => $this->smallInteger(4)->defaultValue(0)->comment('星期'),
                'start_time' => $this->string(10)->defaultValue(null)->comment('开始上课时间'),
                'end_time' => $this->string(10)->defaultValue(null)->comment('结束上课时间'),
                'classroom_attr_id' => $this->integer()->defaultValue(0)->comment('时间id'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%class_manage_time}}');
        }
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m171031_014745_create_manage_time cannot be reverted.\n";

        return false;
    }
    */
}
